package utils;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class FileManager {

	private String path;
	private String filename;
	private String textoXml;
	private File file;

	public FileManager(String path, String filename, String textoXml) {
		super();
		this.path = path;
		this.filename = filename;
		this.textoXml = textoXml;
	}

	public String createFile() {
		try {
			file = new File(path + filename);
			if (file.createNewFile())
				System.out.println("El archivo se ha creado correctamente");
			else {
				System.out.println("No se pudo crear el archivo " + filename + " en " + path);
				return "No se pudo crear el archivo " + filename + " en " + path;
			}
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}

		try {
			FileWriter fstream = new FileWriter(file);
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(textoXml);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return textoXml;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String getFilename() {
		return filename;
	}

	public void setFilename(String filename) {
		this.filename = filename;
	}

	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

}
